/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.sms.client.impl;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.tbit.main.sms.client.dto.SmsSendReqDTO;
import com.tbit.main.sms.enums.template.ChuangLanSmsTemplateEnum;
import com.tbit.main.sms.properties.SmsChannelProperties;
import com.tbit.main.util.ClzySmsAuthUtil;

/**
 * @author <a href="mailto:li.yao@tbit.com.cn">yao</a>
 * @version 4.1.0
 * @since 2024/7/12 9:53
 */
public class ChuangLanSmsClient extends AbstractSmsClient {

    public ChuangLanSmsClient(SmsChannelProperties properties) {
        super(properties);
        Assert.notEmpty(properties.getApiKey(), "apiKey 不能为空");
        Assert.notEmpty(properties.getApiSecret(), "apiSecret 不能为空");
        Assert.notEmpty(properties.getApiTemplateCode(), "apiTemplateCode 不能为空");
    }

    @Override
    protected void doInit() {
    }

    @Override
    protected void doSend(SmsSendReqDTO dto) {

        ChuangLanSmsTemplateEnum template = ChuangLanSmsTemplateEnum.getTemplate(properties.getApiTemplateCode());
        String params = StrUtil.format(template.getParams(), dto.getTemplateParams());

        ClzySmsAuthUtil.sendSms(properties.getApiKey(), properties.getApiSecret(), dto.getMobile(), params);
    }

}
